package com.ytzl.itrip.biz.controller;

import com.ytzl.itrip.beans.model.ItripAreaDic;
import com.ytzl.itrip.beans.model.ItripHotel;
import com.ytzl.itrip.beans.model.ItripLabelDic;
import com.ytzl.itrip.biz.controller.VO.ItripHotelDetailsVO;
import com.ytzl.itrip.utils.common.Dto;
import com.ytzl.itrip.utils.common.DtoUtil;
import com.ytzl.itrip.utils.common.EmptyUtils;
import com.ytzl.itrip.utils.common.ErrorCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/4/25 0025.
 */
@Controller
@RequestMapping("/api/hotel")
@Api(description = "酒店业务模块")
public class HotelController {
    @Resource
    private com.ytzl.itrip.service.ItripAreaDicService itripAreaDicService;
    @Resource
    private com.ytzl.itrip.service.ItripLabelDicService itripLabelDicService;

    @Resource
    private com.ytzl.itrip.service.ItripHotelService itripHotelService;


    @ApiOperation(value = "查询(国内 国外)热门城市",
            httpMethod = "GET", response = Dto.class,
            produces = "application/json",
            notes = "查询国内、国外的热门城市(1:国内 2:国外) 成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：   \\n\" +\n" +
                    "        \"错误码：  \\n\" +\n" +
                    "        \"10202 : 系统异常,获取失败")
    @RequestMapping("/queryhotcity/{type}")
    @ResponseBody
    public Dto queryhotcity(@PathVariable(value = "type")
                            @ApiParam(value = "类型", required = true) int type) {
        //isHot   1热门城市
        //isChina 1国内  2国外
        Map<String, Object> param = new HashMap<>();
        //热门城市
        param.put("isHot", "1");
        param.put("isChina", type);
        List<ItripAreaDicVO> itripAreaDicVOList = new ArrayList<>();
        try {
            List<ItripAreaDic> itripAreaDicList = itripAreaDicService.getItripAreaDicListByMap(param);
            //遍历返回结果，将实体转换为VO类
            for (ItripAreaDic itripAreaDic : itripAreaDicList) {
                ItripAreaDicVO itripAreaDicVO = new ItripAreaDicVO();
                //自动赋值，字段名称类型一致 第一个参数为有值  第二个参数是将要赋值
                BeanUtils.copyProperties(itripAreaDic, itripAreaDicVO);
                itripAreaDicVOList.add(itripAreaDicVO);
            }
            //返回结果
            return DtoUtil.returnDataSuccess(itripAreaDicVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", ErrorCode.BIZ_QUERY_HOTCITY_FAIL);
        }
    }

    @ApiOperation(value = "查询酒店特色列表",
            httpMethod = "GET", response = Dto.class,
            produces = "application/json",
            notes = "获取酒店特色 成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：   \\n\" +\n" +
                    "        \"错误码：  \\n\" +\n" +
                    "        \"10205 : 系统异常,获取失败")
    @RequestMapping(value = "/queryhotelfeature",
            method = RequestMethod.GET,
            produces = "application/json")
    @ResponseBody
    public Dto queryhotelfeature() {
        Map<String, Object> param = new HashMap<>();
        param.put("parentId", "16");
        List<ItripLabelDicVo> itripLabelDicVos = new ArrayList<>();
        try {
            List<ItripLabelDic> itripLabelDicList = itripLabelDicService.getItripLabelDicListByMap(param);
            for (ItripLabelDic itripLabelDic : itripLabelDicList) {
                ItripLabelDicVo itripLabelDicVo1 = new ItripLabelDicVo();
                BeanUtils.copyProperties(itripLabelDic, itripLabelDicVo1);
                itripLabelDicVos.add(itripLabelDicVo1);
            }
            return DtoUtil.returnDataSuccess(itripLabelDicList);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常，获取失败",
                    ErrorCode.BIZ_HOTEL_QUERY_HOTEL_FEATURE_FAIL);
        }
    }


    @ApiOperation(value = "根据城市查询商圈",
            httpMethod = "GET", response = Dto.class,
            produces = "application/json",
            notes = "根据城市查询商圈  \n" +
                    "成功：success = ‘true’ | 失败：success = ‘false’ \n" +
                    "并返回错误码，如下：  \n" +
                    "错误码：  \n" +
                    "10204 : 系统异常,获取失败")
    @RequestMapping(value = "/querytradearea/{cityId}",
            method = RequestMethod.GET,
            produces = "application/json")
    @ResponseBody
    public Dto querytradearea(@PathVariable(value = "cityId")
                              @ApiParam(value = "城市Id", required = true) int cityId) {
        Map<String, Object> param = new HashMap<>();
        param.put("parent", cityId);
        //==1 的时候是商圈
        param.put("isTradingArea", "1");
        List<ItripAreaDicVO> itripAreaDicVOList = new ArrayList<>();
        try {
            List<ItripAreaDic> itripAreaDicList = itripAreaDicService.getItripAreaDicListByMap(param);
            //遍历返回结果，将实体转换为VO类
            for (ItripAreaDic itripAreaDic : itripAreaDicList) {
                ItripAreaDicVO itripAreaDicVO = new ItripAreaDicVO();
                //自动赋值，字段名称类型一致 第一个参数为有值  第二个参数是将要赋值
                BeanUtils.copyProperties(itripAreaDic, itripAreaDicVO);
                itripAreaDicVOList.add(itripAreaDicVO);
            }
            //返回结果
            return DtoUtil.returnDataSuccess(itripAreaDicVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("程序异常,获取失败",
                    ErrorCode.BIZ_HOTEL_QUERY_TRADE_AREA_FAIL);
        }
    }


    @ApiOperation(value = "根据酒店id查询酒店特色、商圈、酒店名称",
            httpMethod = "GET", response = Dto.class,
            produces = "application/json",
            notes = "根据酒店id查询酒店特色、商圈、酒店名称（视频文字描述）\n" +
                    "成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：\n" +
                    "错误码：\n" +
                    "100214 : 获取酒店视频文字描述失败\n" +
                    "100215 : 酒店id不能为空")
    @RequestMapping(value = "/getvideodesc/{hotelId}",
            method = RequestMethod.GET,
            produces = "application/json")
    @ResponseBody
    public Dto getvideodesc(@PathVariable(value = "hotelId")
                            @ApiParam(value = "酒店Id", required = true) int hotelId) {
        if (EmptyUtils.isEmpty(hotelId)) {
            return DtoUtil.returnFail("酒店Id不能为空", ErrorCode.BIZ_GET_VOIDO_DESC_HOTELID_FAIL);
        }
    }

    //酒店特色
    List<String> labelDicStrList = new ArrayList<>();
    List<IripLabelDic> labelDicList = itripHotelService.queryItripHotelFeatureByHotelId(hotelId);
   for(
    ItripLabelDic itripLabelDic :labelDicList)

    {
        labelDicStrList.add(itripLabelDic.getName());
    }

    //酒店商圈
    List<String> areaDicStrList = new ArrayList<>();
    List<ItripAreaDic> itripAreaDicList = itripAreaDicService.queryItripHotelAreaByHotelId(hotelId);
    for(
    ItripLabelDic itripLabelDic :itripAreaDicList)

    {
        areaDicStrList.add(itripLabelDic.getName());
    }

    ;
    //酒店名称
    String hotelName = itripHotelService.getItripHotelByHotelId(hotelId).getHotelName();
catch(
    Exception e)

    {
        e.printStackTrace();
        return DtoUtil.returnFail("获取酒店视频文字描述失败", ErrorCode.BIZ_GET_VIDEO_DESC_FAIL);


    }

    @ApiOperation(value = "根据酒店id查询酒店特色和介绍",
            httpMethod = "GET", response = Dto.class,
            produces = "application/json",
            notes = "根据酒店id查询酒店特色和介绍  \\n\" +\n" +
                    "        \"成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：  \\n\" +\n" +
                    "        \"10210: 酒店id不能为空  \\n\" +\n" +
                    "        \"10211: 系统异常,获取失败")
    @RequestMapping(value = "/getvideodesc/{hotelId}",
            method = RequestMethod.GET,
            produces = "application/json")
    @ResponseBody
    public Dto queryhoteldetail(@PathVariable(value = "id")
                                @ApiParam(value = "酒店Id", required = true) Long id) {
        if (EmptyUtils.isEmpty(id)) {
            return DtoUtil.returnFail("酒店Id不能为空", ErrorCode.BIZ_QUERY_HOTEL_DETATLS_ID_FAIL);
        }

        List<ItripHotelDetailsVO> itripHotelDetailsVOList = new ArrayList<>();
        try {
            ItripHotel itripHotel = itripHotelService.getItripHotelById(id);


            List<ItripLabelDic> labelDicList = itripHotelService.queryItripHotelFeatureByHotelId();
            for (ItripLabelDic itripLabelDic : labelDicList) {
                itripHotelDetailsVOList.add(new ItripHotelDetailsVO(itripLabelDic.getDescription(), itripLabelDic.getName()));

            }
            return DtoUtil.returnDataSuccess(itripHotelDetailsVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败",BIZ_QUERY_HOTEL_DETATLS_FAIL);
        }


    }
    @ApiOperation(value = "根据酒店id查询酒店id查询酒店设施",
            httpMethod = "GET", response = Dto.class,
            produces = "application/json",
            notes = "根据酒店id查询酒店设施  \\n\" +\n" +
                    "        \"成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：  \\n\" +\n" +
                    "        \"10206: 酒店id不能为空  \\n\" +\n" +
                    "        \"10207: 系统异常,获取失败")
    @RequestMapping(value = "/getvideodesc/{hotelId}",
            method = RequestMethod.GET,
            produces = "application/json")
    @ResponseBody
    public Dto queryhotelfacilities(@PathVariable(value = "id")
                                @ApiParam(value = "酒店Id", required = true) Long id) {

        if (EmptyUtils.isEmpty(id)) {
            return DtoUtil.returnFail("酒店Id不能为空", ErrorCode.BIZ_QUERY_HOTEL_DETATLS_ID_FAIL);
        }
        try {
            ItripHotel itripHotel =  itripHotelService.getItripHotelByid(id);
            return DtoUtil.returnDataSuccess(itripHotel.getFacilities());
        }catch (Exception e){
            e.printStackTrace();
            return  DtoUtil.returnFail("系统异常","10207");
        }

    }


    @ApiOperation(value = "根据酒店id查询酒店id查询酒店政策",
            httpMethod = "GET", response = Dto.class,
            produces = "application/json",
            notes = "根据酒店id查询酒店政策  \\n\" +\n" +
                    "        \"成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：  \\n\" +\n" +
                    "        \"10208: 酒店id不能为空  \\n\" +\n" +
                    "        \"10209: 系统异常,获取失败")
    @RequestMapping(value = "/getvideodesc/{Id}",
            method = RequestMethod.GET,
            produces = "application/json")
    @ResponseBody
    public Dto queryhotelfacilities(@PathVariable(value = "id")
                                    @ApiParam(value = "酒店Id", required = true) Long id) {

    }
}